﻿using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace RayDen.Library.Components.Surface.Spectral
{
    public sealed class SpectralDataCache<TSpectra>
    {
        private readonly List<List<TSpectra>> data;

        public SpectralDataCache()
        {
            data = new List<List<TSpectra>>();
        }

        public int AddEntity()
        {
            var entity = new List<TSpectra>();
            this.data.Add(entity);
            return this.data.Count - 1;
        }

        public int AddItem(int entityId, TSpectra value)
        {
            this.data[entityId].Add(value);
            return this.data[entityId].Count - 1;
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public TSpectra Get(int entityId, int itemId)
        {
            return itemId >= data[entityId].Count ? default(TSpectra) : data[entityId][itemId];
        }
    }
}